#!/bin/ash

### PREPARE ENVIRONMENT
RAMDISK_PATH="/mnt/ramdisk"
RAMFILE="ramfile"
RAMFILE_SIZE=2G

# CREATE MOUNTPOINT
if [ ! -d "$RAMDISK_PATH" ]; then
    mkdir -p "$RAMDISK_PATH"
fi

# MOUNT
if ! mountpoint -q "$RAMDISK_PATH"; then
    mount -t tmpfs -o size=2G tmpfs "$RAMDISK_PATH"
fi

# CREATE RAMFILE
pushd "$RAMDISK_PATH"
if [ ! "$RAMFILE" ]; then
    dd if=/dev/zero of="$RAMFILE" bs=1M count=2048
fi
popd

# MAKE
make clean
make

# WRITE 
./SHARE-MEM-WRITE

# SLEEP
sleep 5

# READ
./SHARE-MEM-READ

# CLEAM
make clean
rm -rf "$RAMDISK_PATH/$RAMFILE"
umount "$RAMDISK_PATH"
